package com.franklin.springbootdemo;

import com.franklin.springbootdemo.controller.DemoEntity;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.IntStream;

@Service
public class DemoService {

    @Autowired
    private DemoMapper demoMapper;

    public List<DemoEntity> getDemoEntityList(Integer num) {
        return IntStream.range(0, num)
                .mapToObj(i -> {
                    DemoEntity demoEntity = new DemoEntity();
                    demoEntity.setId("id_" + i);
                    demoEntity.setName("name_" + i);
                    return demoEntity;
                })
                .collect(Collectors.toList());
    }

    public Map<String, Object> getMap() {
        Map<String, Object> map = new HashMap<>();
        map.put("DemoService.getMap.map.1", "value");
        map.put("DemoService.getMap.map.2", 2);
        map.put("DemoService.getMap.map.3", getMap1());
        Map<String, Object> map1 = new HashMap<>();
        map.put("DemoService.getMap.map.4", map1);


        map1.put("DemoService.getMap.map1.1", "value");
        map1.put("DemoService.getMap.map1.2", 2);
        Map<String, Object> map11 = getMap1();
        map1.put("DemoService.getMap.map1.3", map11);
        return map;
    }

    public Map<String, Object> getMap1() {
        Map<String, Object> map = new HashMap<>();
        map.put("DemoService.getMap1.1", "value");
        map.put("DemoService.getMap1.2", 2);
        map.put("DemoService.getMap1.3", getMap2());
        map.putAll(getMap2());

        Map<String, Object> stringObjectMap = (Map<String, Object>) map.get("DemoService.getMap1.3");
        stringObjectMap.get
        return map;
    }

    public Map<String, Object> getMap2() {
        Map<String, Object> map = new HashMap<>();
        map.put("DemoService.getMap2.1", "value");
        map.put("DemoService.getMap2.2", 2);
        return map;
    }

    public Map<String, Object> getMap3() {
        Map<String, Object> map = new HashMap<>();
        map.put("DemoService.getMap3.1", "value");
        map.put("DemoService.getMap3.2", 2);
        return Maps.newHashMap(map);
    }
}
